/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_CustomerCategory;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.format.Formats;
import com.openbravo.bean.CustomerCategory;
import com.openbravo.data.model.Field;

/**
 *
 * @author Administrator
 */
public class CustomerCategoryDAO extends ModifiedLogDAO<CustomerCategory>{

    public CustomerCategoryDAO(I_Session s) {
        super(s);
    }

     @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "CUSTOMERCATEGORIES",
                new Field[]{
                   new Field(I_CustomerCategory.ID,Datas.STRING, Formats.STRING),
                   new Field(I_CustomerCategory.NAME,Datas.STRING, Formats.STRING),
                   new Field(I_CustomerCategory.PARENTID,Datas.STRING, Formats.STRING,CustomerCategory.class),
                   new Field(I_CustomerCategory.ISHOT,Datas.BOOLEAN, Formats.BOOLEAN),
                   new Field(I_CustomerCategory.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_CustomerCategory.CREATEDATE,Datas.TIMESTAMP, Formats.TIMESTAMP)
                } ,
                new int[]{0}){
					@Override
					public String getDefaultListOrder(String alise) {
						String ret=" order by ";
						if(alise!=null)
							ret+=alise+".";
						ret+=I_CustomerCategory.CREATEDATE+" ASC ";
						return ret;
					}
        	
        };

    }

    @Override
    public void writeInsertValues(DataWrite dp, CustomerCategory obj) throws BasicException {
           dp.setString(1, obj.getID());
           dp.setString(2, obj.getName());
           dp.setString(3, obj.getM_sParentID());
           dp.setBoolean(4, obj.isHot());
           dp.setTimestamp(5,obj.getLastModified());
           dp.setTimestamp(6,obj.getCreateDate());
    }


    public CustomerCategory readValues(DataRead dr,CustomerCategory obj) throws BasicException {
        if(obj==null)
        	obj=new CustomerCategory();
        obj.setID(dr.getString(1));
        obj.setName(dr.getString(2));
        obj.setM_sParentID(dr.getString(3));
        obj.setHot(dr.getBoolean(4));
        obj.setLastModified(dr.getTimestamp(5));
        obj.setCreateDate(dr.getTimestamp(6));
        return obj;
    }


    @Override
    public Class getSuportClass() {
        return CustomerCategory.class;
    }

}
